// pages/movie/movie.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        movieList: [
            1296717,
            1293471,
            1428051,
            1301434,
            1308848,
            26703457
        ],
        movie: [],
        casts: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let temp = []
        let tempCasts = []

        for(let i = 0; i < this.data.movieList.length; i++) {
            let _this = this
            wx.request({
                url: "https://douban.uieee.com/v2/movie/subject/" + this.data.movieList[i],
                header: {
                    "Content-Type": "json"
                },
                success: function (ret) {
                    temp.push({
                        images: ret.data.images,
                        title: ret.data.title,
                        year: ret.data.year,
                        rating: ret.data.rating,
                        countries: ret.data.countries
                    })
                    let str = ""
                    for(let i = 0; i < ret.data.casts.length; i++) {
                        if(i == 0) {
                            str = ret.data.casts[i].name
                        } else {
                            str = str + "/" + ret.data.casts[i].name
                        }
                    }
                    tempCasts.push(str)
                
                    console.log(ret.data)
                    _this.setData({
                        movie: temp,
                        casts: tempCasts
                    })
                },
                fail: function (ret) {
                    console.log(ret)
                }
            })
        }
       
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})